package com.dao.impl;

import com.dao.MemberbuyrecordDao;
import com.dao.MemberbuyrecordForMemeberDao;
import com.entity.Memberbuyrecord;
import com.mapper.MemberbuyrecordMapper;
import com.page.PageInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MemberbuyrecordDaoImpl implements MemberbuyrecordDao, MemberbuyrecordForMemeberDao {
    @Resource
    MemberbuyrecordMapper memberbuyrecordMapper;
     public List<Memberbuyrecord> getAll(){
         return memberbuyrecordMapper.getAll();
     }

    /**
     * 普通分页查询
     * @param pageInfo
     * @return
     */
    public List<Memberbuyrecord> getMemberbuyrecordsByPage(PageInfo pageInfo){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount = (int)memberbuyrecordMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
         return memberbuyrecordMapper.getMemberbuyrecordsByPage(map);
    }



    /**
     *
     * @param mbno
     * @return
     */
    public Memberbuyrecord getMemberbuyrecordByMno(Integer mbno) throws Exception{
        return memberbuyrecordMapper.selectByPrimaryKey(mbno);
    }

    /**
     *
     * @param memberbuyrecord
     */
    public Integer add(Memberbuyrecord memberbuyrecord)throws Exception{
        return memberbuyrecordMapper.insertSelective(memberbuyrecord);//是使用selective 有值才插入
    }
    /**
     *  根据主键修改信息
     * @param memberbuyrecord
     */
    public Integer update(Memberbuyrecord memberbuyrecord)throws Exception{
        return memberbuyrecordMapper.updateByPrimaryKeySelective(memberbuyrecord);//是使用selective 有值才插入
    }
}
